package com.sinosoft.cnmuseum.servlets;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sinosoft.cnmuseum.dao.MbMusicGcxxDao;
import com.sinosoft.cnmuseum.dao.flownumDao;
import com.sinosoft.cnmuseum.entity.MbMusicGcxx;
import com.sinosoft.cnmuseum.utils.AcquisitionStartUtils;
import com.sinosoft.cnmuseum.utils.Status;
import com.sinosoft.commontools.annotated.TransAnnotation;
import com.sinosoft.commontools.annotated.rquestMethod;
import com.sinosoft.commontools.annotated.rquestMethod.ReqMode;
import com.sinosoft.commontools.record.Record;

public class StartFlowServlet {


	@rquestMethod(MethodNote = ReqMode.All)
	@TransAnnotation(isTrans=true)
	public Record startflow(HttpServletRequest request, HttpServletResponse response, Record data){
		Record record = new Record();
		record.add(Status.SATUS, Status.OK);
		try {
			HttpSession session = request.getSession(false);
			String userid = (String) session.getAttribute(Status.SESSION_USERID);
			int id = data.getIntValue("id");
			MbMusicGcxxDao dao = new MbMusicGcxxDao();
			Record gcxx = dao.getById(id);
			String collectionCode = gcxx.getStrValue(MbMusicGcxx.COLLECTIONCODE);
			if(dao.getFlowingData(collectionCode)){
				// 流程编目状态，不能启动新的编辑
				record.add(Status.SATUS, Status.FAILED);
				record.add(Status.MSG, "流程已经启动！");
			}else{
				// 启动新编目
				//生成当前成流程数据，并更新流程数据
				int newflowid = new flownumDao().getNewflowid();
				String flowid = "1_"+newflowid + "_bj";
				String flowstep = "数据编辑";
				String lockstatus = "1";
				String isrunning = "1";
				String assigneeusers = "," + userid+",";
				String assigneeuser = userid;
				String assigneerole = "";
				String assigneeroles = "";
				String isnew = "0" ;
				String nextflow = "";
				String nextdesc = "";
				// flowid flowstep nextflow nextdesc isrunning assigneeuser lockstatus assigneeusers
				// 保存流程数据
				// 调用流程工具类 
				AcquisitionStartUtils acutil = new AcquisitionStartUtils();
				int new_id = acutil.getMusicGcxxID(id, flowid, flowstep, nextflow, nextdesc, 
						isrunning, assigneerole, assigneeuser, 
						lockstatus, assigneeroles, assigneeusers,isnew);
				record.add("id", new_id);
			}
		} catch (Exception e) {
			record.add(Status.SATUS, Status.FAILED);
			record.add(Status.MSG, "数据异常！");
		}
		return record;
	}
	
}
